package cst.a214frm.recyclertest214frm.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

import cst.a214frm.recyclertest214frm.adapter.MyAdapter;
import cst.a214frm.recyclertest214frm.R;
import cst.a214frm.recyclertest214frm.bean.ArticleBean;
import cst.a214frm.recyclertest214frm.iface.ArticleListener;
import cst.a214frm.recyclertest214frm.model.ArticleModel;

public class MainActivity extends AppCompatActivity implements ArticleListener {

    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
    private MyAdapter mAdapter;
    List<ArticleBean> list;

    private void initRecyclerView() {
        recyclerView = (RecyclerView) findViewById(R.id.recyclerview);
        //创建默认的线性LayoutManager
        layoutManager = new LinearLayoutManager(this);
        //设置布局管理器
        recyclerView.setLayoutManager(layoutManager);
        //如果可以确定每个item的高度是固定的，设置这个选项可以提高性能
        recyclerView.setHasFixedSize(true);
        //创建并设置Adapter
        //list = getData();
        mAdapter = new MyAdapter(this);
        mAdapter.setList(list);
        recyclerView.setAdapter(mAdapter);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initRecyclerView();
        ArticleModel articleModel=new ArticleModel();
        articleModel.getResultList("article",2,"2ts2j910hv4m270hipde4a67d7",this);
    }

    @Override
    public void onResponse(List<ArticleBean> list) {
        this.list=list;
        mAdapter.setList(list);
    }

    @Override
    public void onFail(String msg) {
        Toast.makeText(this, "fail"+msg, Toast.LENGTH_SHORT).show();
    }
}

    /*private List<ArticleBean> getData() {
        List<ArticleBean> list = new ArrayList<ArticleBean>();
        ArticleBean art;

        for(int i=1;i<7;i++){
            art = new ArticleBean();
            art.setArticleId(1);
            art.setTitle("标题"+i);
            if(i==1)art.setImgid(R.drawable.f1);
            else if(i==2)art.setImgid(R.drawable.f2);
            else if(i==3)art.setImgid(R.drawable.f3);
            else if(i==4)art.setImgid(R.drawable.f4);
            else if(i==5)art.setImgid(R.drawable.f5);
            else if(i==6)art.setImgid(R.drawable.f6);
            art.setTime("2017-4-1 15:16");
            art.setDescription("描述"+i);
            list.add(art);

        }



        return list;
    }


*/

